home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 112_01.zip / DDOCSYS.C < prev    next >
Text File  |  1993-06-19  |  4KB  |  231 lines

  1. /*  TAB s5,4
  2.  *
  3.  *  system dependant functions for diskdoc
  4.  *
  5.  *  required are:
  6.  *  botmem,topmem,sysok,conin,conout,const
  7.  *  seldrv,lnext,read,write,rstdrv
  8.  */
  9.  
  10. /*
  11.  *  this version is for small C and cp/m 8080 version 2.x.
  12.  *  since bios must be used for sector read and write,
  13.  *  character i/o functions use bios directly too.
  14.  *  cp/m "compatible" operating systems will probably
  15.  *  need to have these functions rewritten.
  16.  */
  17.  
  18. char *xlt;    /* sector xlate table, used by cp/m version */
  19.  
  20. /*
  21.  *  return pointer to bottom of free memory
  22.  */
  23.  
  24. int lastglobal;     /* dirty trick, will work in small-c */
  25.  
  26. botmem()
  27. {   return &lastglobal;
  28. }
  29.  
  30. /*
  31.  *  top of free memory
  32.  *  remember that the stack needs some space too
  33.  */
  34.  
  35. topmem()
  36. {   char *p,topofstack;
  37.     p=&topofstack;
  38.     return p-300;
  39. }
  40.  
  41. /*
  42.  *  return true if enviroment seems to be ok
  43.  */
  44.  
  45. sysok()
  46. {   char *p;
  47. #asm
  48.     mvi     c,12    ;check version number
  49.     call    5
  50.     ani     0f0h
  51.     cpi     20h     ;ver 2.x?
  52.     jnz     nogood
  53.     mov     a,h
  54.     ora     a        ;cp/m?
  55.     jz        ok
  56. nogood:
  57.     lxi     h,0     ;false if no good
  58.     pop     d
  59.     ret
  60. ok:
  61. #endasm
  62.     p=1;
  63.     return (*p==3);    /* check if xsub or despool is active */
  64. }
  65.  
  66. /*
  67.  *  return console status, true if ready
  68.  */
  69.  
  70. const()
  71. {   return bios(2,0);
  72. }
  73.  
  74. /*
  75.  *  get character from console, no echo
  76.  */
  77.  
  78. conin()
  79. {   return bios(3,0);
  80. }
  81.  
  82. /*
  83.  *  put character to console
  84.  *  no character conversion should be performed
  85.  */
  86.  
  87. conout(ch)
  88.     char ch;
  89. {   bios(4,ch);
  90. }
  91.  
  92. /*
  93.  *  select drive, drive name is 'a','b' etc.
  94.  *  set values for track, sector counts and first sector
  95.  *  return true if ok
  96.  *  to find out what this version does, 
  97.  *  refer to the cp/m 2.0 alteration guide
  98.  */
  99.  
  100. seldrv(drv,pt,ps,pf)
  101.     char drv;
  102.     int *pt,*ps,*pf;        /* where to put track, sector and firstsector */
  103. {   int *dph,*spt,*dsm,*off,halfsecs,trks;
  104.     char *dpb,*bls;
  105.     if ((dph=bios(9,drv-'a'))==0) return 0;
  106.     xlt=dph[0];         /* look at disk parameter header */
  107.     dpb=dph[5];
  108.     if (xlt) *pf=xlt[0];
  109.     else *pf=255&bios(16,0);
  110.     spt=&dpb[0]; *ps=*spt;  /* and at disk parameter block too */
  111.     bls=&dpb[2];
  112.     dsm=&dpb[5];
  113.     off=&dpb[13];
  114.     /* this is tricky since unsigned divide isn't supported */
  115.     halfsecs=(*dsm+1)<<(*bls-1);
  116.     trks=((halfsecs/(*spt))*2)+(((halfsecs%(*spt))+(*spt-1))/(*spt));
  117.     *pt=trks+*off;
  118.     return 1;
  119. }
  120.  
  121. /*
  122.  *  return next logical track/sector
  123.  *  replace by a call to next() if not required
  124.  *  cp/m version sets sector number according to translate table
  125.  */
  126.  
  127. lnext(t,s)
  128.     int *t,*s;
  129. {   int l;
  130.     if (xlt) {
  131.     l=0;
  132.     while (xlt[l++]!=*s);
  133.     if (l>=sectors) {
  134.         nextt(t);
  135.         l=0;
  136.     }
  137.     *s=xlt[l];
  138.     } else next(t,s);
  139. }
  140.  
  141. /*
  142.  *  reset the currently selected drive
  143.  *  used prior to any other operation on a drive
  144.  *  no error code is returned
  145.  */
  146.  
  147. rstdrv()
  148. {   bios(8,0);
  149. }
  150.  
  151. /*
  152.  *  read sector, false if error
  153.  */
  154.  
  155. read(trk,sec,adr)
  156.     int trk,sec;
  157.     char *adr;
  158. {   bios(10,trk);
  159.     bios(11,sec);
  160.     bios(12,adr);
  161.     if (bios(13,1)) return 0;
  162.     return 1;
  163. }
  164.  
  165. /*
  166.  *  write sector, false if error
  167.  */
  168.  
  169. write(trk,sec,adr)
  170.     int trk,sec;
  171.     char *adr;
  172. {   bios(10,trk);
  173.     bios(11,sec);
  174.     bios(12,adr);
  175.     if (bios(14,1)) return 0;
  176.     return 1;
  177. }
  178.  
  179. /*
  180.  *  bios call
  181.  *  will only work with the original small C
  182.  *  other C compilers will usually have the argument sequence reversed
  183.  */
  184.  
  185. bios(fun,arg)
  186.     int fun,arg;
  187. {   char *ofs;
  188.     ofs=(fun-1)*3;
  189. #asm
  190.     pop     d        ;ofs
  191.     pop     h        ;ret
  192.     pop     b        ;arg
  193.     push    b
  194.     push    h
  195.     push    d
  196.     lhld    1        ;get pointer to bios
  197.     dad     d        ;add offset
  198.     lxi     d,retn1
  199.     push    d
  200.     mov     d,b     ;arg in de too
  201.     mov     e,c
  202.     pchl        ;go
  203. retn1:
  204.     xchg
  205.     mov     l,a
  206.     mvi     h,0
  207.     pop     b        ;ofs
  208.     push    b
  209.     mov     a,c
  210.     cpi     (9-1)*3    ;select disk function?
  211.     jz        retn2
  212.     cpi     (16-1)*3    ;sector translate?
  213.     jnz     retn3
  214. retn2:
  215.     xchg        ;value came in hl
  216. retn3:
  217. #endasm
  218. }
  219.  
  220. /*
  221.  *  some small C library functions need redefinition
  222.  */
  223.  
  224. #asm
  225. ccgo:
  226.     ret
  227. ;
  228. qzexit:
  229.     jmp     0
  230. #endasm
  231.